package com.wk.springboot.jdk8.parallelStream;

import java.time.Duration;
import java.time.Instant;
import java.util.stream.LongStream;

/**
 * @User admin
 * @Date 2020/11/19 17:00
 **/
public class ParallelStreamTest {

    public static void main(String[] args) {
        Instant start = Instant.now();

        long aLong = LongStream.rangeClosed(0L,100000L)
                .parallel()
//            .sequential()//生成串行流
                .sum();//把流转换成并行流

        Instant end = Instant.now();
        System.out.println("Duration.between(start,end).toMillis() = " + Duration.between(start, end).toMillis());
        System.out.println("aLong = " + aLong);
    }

}
